home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / bin / starthttpd.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-06  |  1.2 KB  |  50 lines

  1.  
  2. /* This file is crap. Do not read it. */
  3.  
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9.  
  10. #define FAIL(s) for(;;) { puts(s); exit (20); }
  11.  
  12. int main (int argc, char **argv)
  13. {
  14.     int f;
  15.     static int e = 0;
  16.     struct stat buf;
  17.     
  18.     if (argc > 0)
  19.         FAIL ("No arguments allowed.");
  20.  
  21.     if (stat ("/Apache/bin/httpd", &buf))
  22.         FAIL ("File /Apache/bin/httpd doesn't exist.");
  23.  
  24.     if (buf.st_mode & (S_ISUID | S_ISGID))
  25.         FAIL ("File /Apache/bin/httpd is SUID/SGID!.");
  26.  
  27.     if (stat ("bin/chmod", &buf))
  28.         FAIL ("File /bin/chmod not found - you really want to install the fileutils package. I mean it.");
  29.  
  30.     if (geteuid () && ~geteuid())
  31.         FAIL ("I'm not running as root - is /Apache/bin/starthttpd SUID root?");
  32.  
  33.     printf ("Starting Amiga-Apache....");
  34.     fflush (stdout);
  35.  
  36.     if ((f = vfork ()) < 0)
  37.         FAIL ("vfork() failed.");
  38.  
  39.     if (!f)
  40.     {
  41.      /* close (0); open ("/dev/null", O_RDONLY);
  42.         close (1); open ("/dev/null", O_WRONLY); */
  43.         execl ("/Apache/bin/httpd", "/Apache/bin/httpd", NULL);
  44.         e = 1;
  45.         exit (20);
  46.     }
  47.     printf (e ? "failed!\n" : "ok\n");
  48.     exit (0);
  49. }
  50.